{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "# Creating Pandapower Networks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "This Tutorial will introduce the user into the pandapower datastructure and how to create networks through the pandapower API. The following minimal example contains the most commont elements that are supported by the Pandapower format. For an example that contains all pandapower elements (3 winding transformers, ward equivalents, impedances), see the [advanced tutorial](create_advanced.ipynb) for network creation.\n",
    "\n",
    "<img src=\"pics/example_network_simple.png\">\n",
    "\n",
    "The datastructure of the pandapower framework is based on the python library pandas. A pandapower network consist of a separate element table for each element type that is used in the network. Each element table consists of a column for each parameter and a row for each element. By executing the follwing code cells you generate the various element tables.  You can find detailed descriptions about each parameter in the pandapower documentation under bulletpoint \"Datastructures and Elements\"."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Empty Network"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First, we import pandapower an create an empty network:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "import pandapower as pp #import pandapower\n",
    "\n",
    "net = pp.create_empty_network() #create an empty network"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Buses"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"pics/example_network_simple_buses.png\">\n",
    "\n",
    "We now create the three high voltage (vn_kv=110.) and four medium voltage (vn_kv=20.) buses."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "bus1 = pp.create_bus(net, name=\"HV Busbar\", vn_kv=110, type=\"b\")\n",
    "bus2 = pp.create_bus(net, name=\"HV Busbar 2\", vn_kv=110, type=\"b\")\n",
    "bus3 = pp.create_bus(net, name=\"HV Transformer Bus\", vn_kv=110, type=\"n\")\n",
    "bus4 = pp.create_bus(net, name=\"MV Transformer Bus\", vn_kv=20, type=\"n\")\n",
    "bus5 = pp.create_bus(net, name=\"MV Main Bus\", vn_kv=20, type=\"b\")\n",
    "bus6 = pp.create_bus(net, name=\"MV Bus 1\", vn_kv=20, type=\"b\")\n",
    "bus7 = pp.create_bus(net, name=\"MV Bus 2\", vn_kv=20, type=\"b\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Bus 3 and bus 4 are classified as nodes (type=\"n\"), all other bus types are declared as busbars (type=\"b\"):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>vn_kv</th>\n",
       "      <th>type</th>\n",
       "      <th>zone</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HV Busbar</td>\n",
       "      <td>110.0</td>\n",
       "      <td>b</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HV Busbar 2</td>\n",
       "      <td>110.0</td>\n",
       "      <td>b</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HV Transformer Bus</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MV Transformer Bus</td>\n",
       "      <td>20.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>MV Main Bus</td>\n",
       "      <td>20.0</td>\n",
       "      <td>b</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>MV Bus 1</td>\n",
       "      <td>20.0</td>\n",
       "      <td>b</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>MV Bus 2</td>\n",
       "      <td>20.0</td>\n",
       "      <td>b</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 name  vn_kv type  zone  in_service\n",
       "0           HV Busbar  110.0    b  None        True\n",
       "1         HV Busbar 2  110.0    b  None        True\n",
       "2  HV Transformer Bus  110.0    n  None        True\n",
       "3  MV Transformer Bus   20.0    n  None        True\n",
       "4         MV Main Bus   20.0    b  None        True\n",
       "5            MV Bus 1   20.0    b  None        True\n",
       "6            MV Bus 2   20.0    b  None        True"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.bus # show bus table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All create functions return the pandapower index of the element that was created, for example the variable bus6 is now equal to the index of the bus with the name \"MV Station 2\" (which is 5):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bus6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We use these variables for creating bus and branch elements in the following."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### External Grid"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"pics/example_network_simple_ext_grid.png\">\n",
    "\n",
    "We now create an external grid connection that serves as slack node for the power flow calculation. The voltage of the external grid is set to a magnitude of 1.02 per unit and 50 degrees voltage angle:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>vm_pu</th>\n",
       "      <th>va_degree</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.02</td>\n",
       "      <td>50.0</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   name  bus  vm_pu  va_degree  in_service\n",
       "0  None    0   1.02       50.0        True"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_ext_grid(net, bus1, vm_pu=1.02, va_degree=50) # Create an external grid connection\n",
    "\n",
    "net.ext_grid #show external grid table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Transformer "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"pics/example_network_simple_trafo.png\">\n",
    "\n",
    "The transformer connects the high-voltage with the medium-voltage side of the grid. The high-voltage bus of the transformer is connected to Bus3 and on the medium-voltage side the transformer is linked to Bus4. We select the standard type \"25 MVA 110/20 kV\" from the pandapower basic standard type library:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "trafo1 = pp.create_transformer(net, bus3, bus4, name=\"110kV/20kV transformer\", std_type=\"25 MVA 110/20 kV\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " The detailled transformer parameters, such as short circuit voltages, rated power or iron losses are automatically loaded from the standard type library (see [standard type library tutorial](std_types.ipynb)) and stored in the transformer table:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>std_type</th>\n",
       "      <th>hv_bus</th>\n",
       "      <th>lv_bus</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>vn_hv_kv</th>\n",
       "      <th>vn_lv_kv</th>\n",
       "      <th>vk_percent</th>\n",
       "      <th>vkr_percent</th>\n",
       "      <th>pfe_kw</th>\n",
       "      <th>...</th>\n",
       "      <th>tap_neutral</th>\n",
       "      <th>tap_min</th>\n",
       "      <th>tap_max</th>\n",
       "      <th>tap_step_percent</th>\n",
       "      <th>tap_step_degree</th>\n",
       "      <th>tap_pos</th>\n",
       "      <th>tap_phase_shifter</th>\n",
       "      <th>parallel</th>\n",
       "      <th>df</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>110kV/20kV transformer</td>\n",
       "      <td>25 MVA 110/20 kV</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>25.0</td>\n",
       "      <td>110.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.41</td>\n",
       "      <td>14.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>-9</td>\n",
       "      <td>9</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>False</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                     name          std_type  hv_bus  lv_bus  sn_mva  vn_hv_kv  \\\n",
       "0  110kV/20kV transformer  25 MVA 110/20 kV       2       3    25.0     110.0   \n",
       "\n",
       "   vn_lv_kv  vk_percent  vkr_percent  pfe_kw     ...      tap_neutral  \\\n",
       "0      20.0        12.0         0.41    14.0     ...                0   \n",
       "\n",
       "   tap_min tap_max  tap_step_percent  tap_step_degree  tap_pos  \\\n",
       "0       -9       9               1.5              0.0        0   \n",
       "\n",
       "   tap_phase_shifter  parallel   df  in_service  \n",
       "0              False         1  1.0        True  \n",
       "\n",
       "[1 rows x 23 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.trafo #show transformer table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lines"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The network includes three medium voltage lines and one high voltage line. The bus connections and line lengths are defined in the network diagram:\n",
    "\n",
    "<img src=\"pics/example_network_simple_lines.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The line parameters are once again taken from the standard type library (see [standard type library tutorial](std_types.ipynb)). We use different line lengths and standard types for each line:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "line1 = pp.create_line(net, bus1, bus2, length_km=10, std_type=\"N2XS(FL)2Y 1x300 RM/35 64/110 kV\",  name=\"Line 1\")\n",
    "line2 = pp.create_line(net, bus5, bus6, length_km=2.0, std_type=\"NA2XS2Y 1x240 RM/25 12/20 kV\", name=\"Line 2\")\n",
    "line3 = pp.create_line(net, bus6, bus7, length_km=3.5, std_type=\"48-AL1/8-ST1A 20.0\", name=\"Line 3\")\n",
    "line4 = pp.create_line(net, bus7, bus5, length_km=2.5, std_type=\"NA2XS2Y 1x240 RM/25 12/20 kV\", name=\"Line 4\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The full line table looks like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>std_type</th>\n",
       "      <th>from_bus</th>\n",
       "      <th>to_bus</th>\n",
       "      <th>length_km</th>\n",
       "      <th>r_ohm_per_km</th>\n",
       "      <th>x_ohm_per_km</th>\n",
       "      <th>c_nf_per_km</th>\n",
       "      <th>g_us_per_km</th>\n",
       "      <th>max_i_ka</th>\n",
       "      <th>df</th>\n",
       "      <th>parallel</th>\n",
       "      <th>type</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Line 1</td>\n",
       "      <td>N2XS(FL)2Y 1x300 RM/35 64/110 kV</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0600</td>\n",
       "      <td>0.144</td>\n",
       "      <td>144.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.588</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Line 2</td>\n",
       "      <td>NA2XS2Y 1x240 RM/25 12/20 kV</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.1220</td>\n",
       "      <td>0.112</td>\n",
       "      <td>304.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.421</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Line 3</td>\n",
       "      <td>48-AL1/8-ST1A 20.0</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>3.5</td>\n",
       "      <td>0.5939</td>\n",
       "      <td>0.372</td>\n",
       "      <td>9.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.210</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Line 4</td>\n",
       "      <td>NA2XS2Y 1x240 RM/25 12/20 kV</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "      <td>2.5</td>\n",
       "      <td>0.1220</td>\n",
       "      <td>0.112</td>\n",
       "      <td>304.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.421</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     name                          std_type  from_bus  to_bus  length_km  \\\n",
       "0  Line 1  N2XS(FL)2Y 1x300 RM/35 64/110 kV         0       1       10.0   \n",
       "1  Line 2      NA2XS2Y 1x240 RM/25 12/20 kV         4       5        2.0   \n",
       "2  Line 3                48-AL1/8-ST1A 20.0         5       6        3.5   \n",
       "3  Line 4      NA2XS2Y 1x240 RM/25 12/20 kV         6       4        2.5   \n",
       "\n",
       "   r_ohm_per_km  x_ohm_per_km  c_nf_per_km  g_us_per_km  max_i_ka   df  \\\n",
       "0        0.0600         0.144        144.0          0.0     0.588  1.0   \n",
       "1        0.1220         0.112        304.0          0.0     0.421  1.0   \n",
       "2        0.5939         0.372          9.5          0.0     0.210  1.0   \n",
       "3        0.1220         0.112        304.0          0.0     0.421  1.0   \n",
       "\n",
       "   parallel type  in_service  \n",
       "0         1   cs        True  \n",
       "1         1   cs        True  \n",
       "2         1   ol        True  \n",
       "3         1   cs        True  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.line # show line table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Switches"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are two circuit breakers on the high- and low voltage side of the transformer which connect two buses (Bus2-Bus3 and Bus4-Bus5). These bus-bus switches can be defined with et=\"b\". \n",
    "<img src=\"pics/example_network_simple_switches.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "sw1 = pp.create_switch(net, bus2, bus3, et=\"b\", type=\"CB\", closed=True)\n",
    "sw2 = pp.create_switch(net, bus4, bus5, et=\"b\", type=\"CB\", closed=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Furthermore, we equip all bus/line connections in the medium voltage level with load break switches (\"LBS\") as shown in the network diagram. Bus/Line switches are defined with et=\"l\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "sw3 = pp.create_switch(net, bus5, line2, et=\"l\", type=\"LBS\", closed=True)\n",
    "sw4 = pp.create_switch(net, bus6, line2, et=\"l\", type=\"LBS\", closed=True)\n",
    "sw5 = pp.create_switch(net, bus6, line3, et=\"l\", type=\"LBS\", closed=True)\n",
    "sw6 = pp.create_switch(net, bus7, line3, et=\"l\", type=\"LBS\", closed=False)\n",
    "sw7 = pp.create_switch(net, bus7, line4, et=\"l\", type=\"LBS\", closed=True)\n",
    "sw8 = pp.create_switch(net, bus5, line4, et=\"l\", type=\"LBS\", closed=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The switch table now shows all switches. The bus colum contains the index of the bus the switch is connected to. For bus switches (et=\"b\"), the element column contains the index of the second bus the switch connects to. For line switches (et=\"l\"), the element column contains the index of the line the switch connects to. All switches are closed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bus</th>\n",
       "      <th>element</th>\n",
       "      <th>et</th>\n",
       "      <th>type</th>\n",
       "      <th>closed</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>False</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   bus  element et type  closed  name\n",
       "0    1        2  b   CB    True  None\n",
       "1    3        4  b   CB    True  None\n",
       "2    4        1  l  LBS    True  None\n",
       "3    5        1  l  LBS    True  None\n",
       "4    5        2  l  LBS    True  None\n",
       "5    6        2  l  LBS   False  None\n",
       "6    6        3  l  LBS    True  None\n",
       "7    4        3  l  LBS    True  None"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.switch # show switch table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load\n",
    "\n",
    "<img src=\"pics/example_network_simple_load.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The load element is used to model by default constant active and reactive power consumption. We create a 2 MW / 4 MVar load with a scaling factor of 0.6:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>const_z_percent</th>\n",
       "      <th>const_i_percent</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>scaling</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>load</td>\n",
       "      <td>6</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.6</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   name  bus  p_mw  q_mvar  const_z_percent  const_i_percent  sn_mva  scaling  \\\n",
       "0  load    6   2.0     4.0              0.0              0.0     NaN      0.6   \n",
       "\n",
       "   in_service  type  \n",
       "0        True  None  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_load(net, bus7, p_mw=2, q_mvar=4, scaling=0.6, name=\"load\")\n",
    "\n",
    "net.load"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Voltage dependent loads - ZIP load model\n",
    "One can observe load parameters `const_z_percent` and `const_i_percent` which are set to 0 by default. They can be used in order to define part of a load which is voltage-dependent using the so-called **ZIP load** model, which allows a load definition as a composition of constant power, constant current and constant impedance.  \n",
    "\n",
    "As an example, we create a 2 MW / 4 MVar load with 30% of constant impedance and 20% of constant current:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>const_z_percent</th>\n",
       "      <th>const_i_percent</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>scaling</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>load</td>\n",
       "      <td>6</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.6</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>zip_load</td>\n",
       "      <td>6</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       name  bus  p_mw  q_mvar  const_z_percent  const_i_percent  sn_mva  \\\n",
       "0      load    6   2.0     4.0              0.0              0.0     NaN   \n",
       "1  zip_load    6   2.0     4.0             30.0             20.0     NaN   \n",
       "\n",
       "   scaling  in_service  type  \n",
       "0      0.6        True  None  \n",
       "1      1.0        True  None  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_load(net, bus7, p_mw=2, q_mvar=4, const_z_percent=30, const_i_percent=20, name=\"zip_load\")\n",
    "\n",
    "net.load"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Static Generator\n",
    "\n",
    "<img src=\"pics/example_network_simple_sgen.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The static generator element is used to model constant active and reactive power generation. Since the signing system used in pandapower is always from a consumers point of view, the active power has to be negative to model generation. We create a static generator with 2 MW generation and 500 kVar."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>scaling</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "      <th>current_source</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>static generator</td>\n",
       "      <td>6</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               name  bus  p_mw  q_mvar  sn_mva  scaling  in_service  type  \\\n",
       "0  static generator    6   2.0    -0.5     NaN      1.0        True  None   \n",
       "\n",
       "   current_source  \n",
       "0            True  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_sgen(net, bus7, p_mw=2, q_mvar=-0.5, name=\"static generator\")\n",
    "\n",
    "net.sgen"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Voltage controlled Generator\n",
    "\n",
    "<img src=\"pics/example_network_simple_gen.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The generator element is used to model voltage controlled active power generation. We define it with a active power generation (negative) and a voltage set point:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>vm_pu</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>min_q_mvar</th>\n",
       "      <th>max_q_mvar</th>\n",
       "      <th>scaling</th>\n",
       "      <th>slack</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>generator</td>\n",
       "      <td>5</td>\n",
       "      <td>6.0</td>\n",
       "      <td>1.03</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name  bus  p_mw  vm_pu  sn_mva  min_q_mvar  max_q_mvar  scaling  \\\n",
       "0  generator    5   6.0   1.03     NaN        -3.0         3.0      1.0   \n",
       "\n",
       "   slack  in_service  type  \n",
       "0  False        True  None  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_gen(net, bus6, p_mw=6, max_q_mvar=3, min_q_mvar=-3, vm_pu=1.03, name=\"generator\") \n",
    "\n",
    "net.gen"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Shunt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "\n",
    "<img src=\"pics/example_network_simple_shunt.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The shunt is defined by its active and reactive power consumption at rated voltage. Once again, the signing system is from a consumers point of view. We want to model a a capacitator bank, and therefore have to assign a negative reactive power to the shunt:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bus</th>\n",
       "      <th>name</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>vn_kv</th>\n",
       "      <th>step</th>\n",
       "      <th>max_step</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>Shunt</td>\n",
       "      <td>-0.96</td>\n",
       "      <td>0.0</td>\n",
       "      <td>110.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   bus   name  q_mvar  p_mw  vn_kv  step  max_step  in_service\n",
       "0    2  Shunt   -0.96   0.0  110.0     1         1        True"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_shunt(net, bus3, q_mvar=-0.96, p_mw=0, name='Shunt')\n",
    "\n",
    "net.shunt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you want to learn how to create more complicated networks, continue with the [advanced create tutorial](create_advanced.ipynb). If you want to learn about how to run a loadflow, continue with the [power flow tutorial](powerflow.ipynb). "
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
